package tech.edwardvan.quartzdemo.entity;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.quartz.JobDetail;

import java.util.List;
import java.util.Map;

/**
 * Job数据类
 *
 * @author EdwardVan
 */
@Data
@ApiModel("任务数据类")
public class Task {

    @ApiModelProperty(value = "任务id", required = true)
    private String taskId;
    @ApiModelProperty(value = "调度表达式集合", required = true)
    private List<String> crons;
    @ApiModelProperty(value = "任务描述")
    private String desc;
    @ApiModelProperty(value = "任务数据")
    private Map<String, Object> dataMap;

    public static Task getInstance(JobDetail jobDetail) {
        Task task = new Task();
        task.setTaskId(jobDetail.getKey().getName());
        task.setDesc(jobDetail.getDescription());
        task.setDataMap(jobDetail.getJobDataMap().getWrappedMap());
        return task;
    }
}
